package com.qsl.ssyx.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.sys.service.WareService;
import com.qsl.ssyx.common.result.Result;
import com.qsl.ssyx.model.sys.Ware;
import com.qsl.ssyx.vo.product.WareQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 仓库表 前端控制器
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-08
 */
@Api(tags = "仓库接口")
@RestController
@RequestMapping("/admin/sys/ware")
public class WareController {

    @Autowired
    private WareService wareService;

    @ApiOperation("查询所有")
    @GetMapping("findAllList")
    public Result selectPage() {
        List<Ware> wareList = wareService.list(null);
        return Result.ok(wareList);
    }

    @ApiOperation("条件分页查询")
    @GetMapping("{page}/{limit}")
    public Result selectPage(@ApiParam(value = "当前页") @PathVariable Integer page
            , @ApiParam(value = "每页记录数") @PathVariable Integer limit
            , @ApiParam(value = "关键字") WareQueryVo wareQueryVo) {
        Page<Ware> pageParam = new Page<>(page, limit);
        IPage<Ware> model = wareService.selectPage(pageParam, wareQueryVo);
        return Result.ok(model);
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(@RequestBody Ware ware) {
        boolean flag = wareService.save(ware);
        return Result.ok(flag);
    }

    @ApiOperation("根据Id查询")
    @PostMapping("getById/{Id}")
    public Result save(@ApiParam(value = "Id") @PathVariable Integer Id) {
        Ware ware = wareService.getById(Id);
        return Result.ok(ware);
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public Result update(@RequestBody Ware ware) {
        boolean flag = wareService.updateById(ware);
        return Result.ok(flag);
    }

    @ApiOperation("删除")
    @DeleteMapping("remove/{Id}")
    public Result remove(@PathVariable Integer Id) {
        boolean flag = wareService.removeById(Id);
        return Result.ok(flag);
    }


}

